package com.google.code.opengw.support;

import java.text.MessageFormat;

public class OpenGWException extends Exception{
	
	private static final long serialVersionUID = -5842563822137771441L;
	
	public static final String CONFIG_FILE_NOT_FOUND = "config.xml not found";
	public static final String PUBLISH_FILE_NOT_FOUND = "{0} not found";
	public static final String PUBLISH_DIRECTORY_CAN_NOT_CREATED = "{0} can not created";
	public static final String DOMAIN_DIRECTORY_NOT_FOUND = "domains directory not found";
	public static final String NAMED_DOMAIN_DIRECTORY_NOT_FOUND = "{0} named domain directory not found";
	public static final String DEPLOY_DIRECTORY_NOT_FOUND = "deploy directory not found";
	public static final String PUBLISH_DIRECTORY_NOT_REMOVED = "publish directory not removed";
	public static final String DIRECTORY_NOT_FOUND = "directory not found : {0}";
	
	
	public static final String ELEMENT_NOT_FOUND = "{0} element not found {1}";
	public static final String VALUE_NOT_FOUND = "{0} element's value not found {1}";
	public static final String ATTRIBUTE_NOT_FOUND = "{0} element's {1} attribute not found {1}";
	public static final String CONFIG_FILE_DOMAIN_NOT_FOUND = "No domain found in config.xml";
	public static final String DOMAIN_NOT_FOUND = "{0} named domain not found";
	public static final String DOMAIN_ALREADY_EXIST = "{0} named domain already exist";
	public static final String DOMAIN_NAME_IS_INCORRECT = "{0} named publish not belong to {1} named domain";
	public static final String POLICY_USER_NOT_FOUND = "{0} named policy-user not found";
	public static final String POLICY_USER_ALREADY_EXISTS = "{0} named policy-user already exists";
	public static final String ROUTE_NOT_FOUND_IN_PUBLISH = "There is no route in {0} named publish";
	public static final String INITIALIZATION_NOT_COMPLETED = "Initialization not completed";
	public static final String INITIALIZATION_ALREADY_COMPLETED = "Initialization already completed";
	
	public static final String PUBLISH_NOT_FOUND = "{0} named publish not found";
	public static final String PUBLISH_ALREADY_EXIST = "{0} named publish already exist in {1} named domain";
	
	public static final String INVALID_ROUTE_URL = "Invalid route URL in \"{0}\" named route : \"{1}\"";
	public static final String INVALID_REQUEST_PATH = "Invalid requestpath in \"{0}\" named route : \"{1}\"";
	public static final String ONLY_ONE_CUSTOM_OPERATION_POLICY = "More than one custom operation policy in {0} named route";
	public static final String REQUEST_PATH_ALREADY_EXIST = "{0} named requestPath already exist";
	public static final String ROUTE_NEEDED_FOR_PUBLISH = "There is no route URL or no resource URL or a custom operation policy for in publish.xml, route name : {0}";
	public static final String ROUTE_RESOURCE_NOT_FOUND = "Resource not found : {0}";
	public static final String ROUTE_NAME_ALREADY_EXIST = "{0} named route already exist";
	public static final String INVALID_POLICY_CLASS = "Invalid policy class : {0}";
	public static final String UNSUPPORTED_HTTP_METHOD = "Unsupported HTTP Method : {0}";
	
	public static final String CERTIFICATE_NOT_FOUND_IN_TRUSTSTORE = "Certificate not found at truststore";
	public static final String CERTIFICATE_SUBJECTDNCN_NOT_FOUND = "Certificates subject DN not found";
	public static final String CERTIFICATE_ISSUERDNCN_NOT_FOUND = "Certificates subject DN not found";
	
	public static final String QUEUE_SIZE_EXCEED = "Queue size exceed";
	public static final String POOL_LIMIT_EXCEED = "Pool limit exceed";
	
	public static final String NOT_FOUND_REQUEST_URL = "NOT_FOUND_REQUEST_URL : {0}";
	public static final String METHOD_NOT_ALLOWED = "METHOD_NOT_ALLOWED : {0}";
	
	private int httpCode;
	
	public OpenGWException(String message){
		super(message);
		httpCode = 500;
	}
	
	public OpenGWException(String message, int httpCode){
		super(message);
		this.httpCode = httpCode;
	}
	
	public OpenGWException(String message, Object ... params){
		super(format(message, params));
		httpCode = 500;
	}
	
	public OpenGWException(String message, Throwable cause, Object ... params){
		super(format(message, params), cause);
		httpCode = 500;
	}
	
	public OpenGWException(String message, int httpCode, Object ... params){
		super(format(message, params));
		this.httpCode = httpCode;
	}
	
	public OpenGWException(String message, Throwable cause) {
		super(message, cause);
		httpCode = 500;
	}
	
	public static String format(String message, Object ... params){
		final MessageFormat mf = new MessageFormat(message);
		return mf.format(params);
	}
	
	public int getHttpCode(){
		return httpCode;
	}
}
